<?php
class PNNewItemArray extends PNObjectArray {
  function PNNewItemArray($init=null, $where='')
  {
    $this->PNObject();

    $this->_objType       = 'ishopstore_item';
    $this->_objField      = 'id';
    $this->_objPath       = 'form';

    $this->_init($init, $where);
  }

  function genSort(){
      return 'ORDER BY itm_cr_date DESC';
  }

  function genFilter(){
    $filter  = FormUtil::getPassedValue ('filter', false);
    $keyword = DataUtil::formatForStore($filter['keyword']);
    $type = DataUtil::formatForStore($filter['type']);
    $user_id = FormUtil::getPassedValue ('user_id', false);
    $category_id = DataUtil::formatForStore($filter['category_id']);

    $wheres = array();
    //filter by selector
    if ($category_id && intval($category_id)) $wheres[] = "itm_category_id ='$category_id'";

    //filter by user_id
    $user_id = DataUtil::formatForStore(FormUtil::getPassedValue ('user_id', false));
    if ($user_id) $wheres[] = "itm_cr_uid = '$user_id'";
    //filter not sold out
    //$wheres[] = "itm_type_id <> '3' ";
    ///var_dump($user_id); exit;
    return implode(' AND ', $wheres) ;
  }

  function selectExtendResult(){
    $user_id = DataUtil::formatForStore(FormUtil::getPassedValue ('user_id', false));
    $result = array();
    if ($user_id){
      $result['user'] = InnoUtil::getUserInfo($user_id);
    }
    return $result;
  }
}